package com.hb.trade.server.project.file.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.hb.core.pojo.enums.FirstReviewItemTypeEnum;
import com.hb.core.pojo.project.evaluation.dto.EvaluationThirdDTO;
import com.hb.core.pojo.project.evaluation.entity.EvaluationCommitteeMembers;
import com.hb.core.pojo.project.evaluation.entity.EvaluationSecond;
import com.hb.core.pojo.project.file.dto.*;
import com.hb.core.pojo.project.file.entity.ReviewEvaluationForm;
import com.hb.core.pojo.project.opening.entity.OpeningBidTender;
import com.hb.core.pojo.project.section.dto.BidSectionDTO;
import com.hb.trade.server.project.evaluation.service.EvaluationCommitteeMembersService;
import com.hb.trade.server.project.evaluation.service.EvaluationSecondService;
import com.hb.trade.server.project.evaluation.service.EvaluationThirdService;
import com.hb.trade.server.project.file.manager.ReviewEvaluationFormManager;
import com.hb.trade.server.project.file.service.ReviewEvaluationFormService;
import com.hb.trade.server.project.file.service.ReviewItemSecondService;
import com.hb.trade.server.project.file.service.ReviewItemThirdService;
import com.hb.trade.server.project.opening.service.OpeningBidTenderService;
import com.hb.trade.server.project.section.service.raw.BidSectionService;
import org.fzzn.core.model.msg.Message;
import org.fzzn.core.util.MsgUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 评审表格 前端控制器
 * </p>
 *
 * @author zhongdl
 * @since 2022-04-19
 */
@RestController
public class ReviewEvaluationFormController {
    protected final ReviewEvaluationFormService reviewEvaluationFormService;
    protected final ReviewItemSecondService reviewItemSecondService;
    protected final ReviewItemThirdService reviewItemThirdService;
    protected final BidSectionService bidSectionService;
    protected final EvaluationSecondService evaluationSecondService;
    protected final EvaluationThirdService evaluationThirdService;
    protected final EvaluationCommitteeMembersService evaluationCommitteeMembersService;
    protected final OpeningBidTenderService openingBidTenderService;

    public ReviewEvaluationFormController(ReviewEvaluationFormService reviewEvaluationFormService,
                                          ReviewItemSecondService reviewItemSecondService,
                                          ReviewItemThirdService reviewItemThirdService,
                                          BidSectionService bidSectionService,
                                          EvaluationSecondService evaluationSecondService,
                                          EvaluationThirdService evaluationThirdService,
                                          EvaluationCommitteeMembersService evaluationCommitteeMembersService, OpeningBidTenderService openingBidTenderService) {
        this.reviewEvaluationFormService = reviewEvaluationFormService;
        this.reviewItemSecondService = reviewItemSecondService;
        this.reviewItemThirdService = reviewItemThirdService;
        this.bidSectionService = bidSectionService;
        this.evaluationSecondService = evaluationSecondService;
        this.evaluationThirdService = evaluationThirdService;
        this.evaluationCommitteeMembersService = evaluationCommitteeMembersService;
        this.openingBidTenderService = openingBidTenderService;
    }

    /**
     * @param reviewEvaluationGenerateFormDTO:
     * @Description:生成表格(无表格记录先生成)
     * @Author: zhongdl
     * @Date:2022/4/19 10:58
     * @return: {@link Message <  ReviewEvaluationGenerateFormDTO > }
     **/
    @PostMapping("/reviewEvaluationForm/generate")
    public Message<List<ReviewEvaluationFormDTO>> generate(@RequestBody ReviewEvaluationGenerateFormDTO reviewEvaluationGenerateFormDTO){

        List<ReviewEvaluationFormDTO> list = reviewEvaluationFormService.listReviewEvaluationGenerate(reviewEvaluationGenerateFormDTO.getSectionId(), reviewEvaluationGenerateFormDTO.getFileId());
        //如果表格生成不为空则直接返回 否则生成表格
        if (CollUtil.isNotEmpty(list)){
            return MsgUtil.success(list);
        }
        //生成表格
        ReviewEvaluationFormManager reviewEvaluationFormManager = new ReviewEvaluationFormManager();
        reviewEvaluationGenerateFormDTO.to(reviewEvaluationFormManager);
        List<ReviewEvaluationForm> reviewEvaluationForms = reviewEvaluationFormManager.generateReviewEvaluationForm();
        boolean save = reviewEvaluationFormService.saveBatch(reviewEvaluationForms);
        List<ReviewEvaluationFormDTO> reviewEvaluationFormDTOS = BeanUtil.copyToList(reviewEvaluationForms, ReviewEvaluationFormDTO.class);
        return MsgUtil.success(reviewEvaluationFormDTOS);
    }

    /**
     * @param reviewEvaluationFormDTO:
     * @Description:更新评标表格的生成状态
     * @Author: zhongdl
     * @Date:2022/4/20 15:25

     * @return: {@link org.fzzn.core.model.msg.Message<java.lang.Boolean> }
     **/
    @PostMapping("/reviewEvaluationForm/updateReviewEvaluationForm")
    public Message<Boolean> updateReviewEvaluationForm(@RequestBody ReviewEvaluationFormDTO reviewEvaluationFormDTO){
        if (reviewEvaluationFormDTO.getId() == null){
            return MsgUtil.success(true);
        }
        reviewEvaluationFormDTO.buildBaseData(2);
        boolean update = reviewEvaluationFormService.updateById(reviewEvaluationFormDTO);
        return MsgUtil.success(update);
    }



    @PostMapping("/reviewEvaluationForm/preliminary")
    public Message<List<ReviewItemSecondDto>> preliminary(@RequestParam Long sectionId){
        List<ReviewItemSecondDto> reviewItemSecondDtos = reviewItemSecondService.listReviewItemSecond(sectionId,FirstReviewItemTypeEnum.PRELIMINARY_REVIEW.getCode());
        if (CollUtil.isEmpty(reviewItemSecondDtos)){
            return MsgUtil.success(reviewItemSecondDtos);
        }
        BidSectionDTO bidSectionDTO = bidSectionService.findBidAndProjectBySectionId(sectionId);
        if (bidSectionDTO != null){
            bidSectionDTO.setId(null);
        }
        //查询专家列表
        List<EvaluationCommitteeMembers> membersList = evaluationCommitteeMembersService.findBySectionId(sectionId);

        for (ReviewItemSecondDto reviewItemSecondDto : reviewItemSecondDtos) {
            //评标表格id
            Long evaluationFormId = reviewEvaluationFormService.getReviewEvaluationFormDTO(sectionId, reviewItemSecondDto.getFileId(), 2, FirstReviewItemTypeEnum.PRELIMINARY_REVIEW.getCode(),reviewItemSecondDto.getId(),null);
            reviewItemSecondDto.setEvaluationFormId(evaluationFormId);
            //查询三级评审项
            List<ReviewItemThirdDto> reviewItemThirdDtos = reviewItemThirdService.selectReviewItemThirdListBySecondReviewItemId(reviewItemSecondDto.getId());
            reviewItemSecondDto.setReviewItemThirdDtos(reviewItemThirdDtos);
            //设置项目名称
            bidSectionDTO.to(reviewItemSecondDto);

            //查询二级评审点
            List<EvaluationSecond> evaluationSeconds = evaluationSecondService.findBySectionIdAndSecondId(sectionId, reviewItemSecondDto.getId());
            reviewItemSecondDto.setEvaluationSeconds(evaluationSeconds);
            //查询三级评审点
            List<EvaluationThirdDTO> evaluationThirdDTOS = evaluationThirdService.resultOfReviewPoint(sectionId, reviewItemSecondDto.getId());
            reviewItemSecondDto.setEvaluationThirdDTOS(evaluationThirdDTOS);
            //查询二级未被淘汰的公司
            List<EvaluationSecond> orgIdList = evaluationSecondService.listNotEliminate(sectionId, reviewItemSecondDto.getId());
            reviewItemSecondDto.setOrgIdList(orgIdList);
            reviewItemSecondDto.setMembersList(membersList);
        }
        return MsgUtil.success(reviewItemSecondDtos);
    }

    /**
     * @param sectionId:
     * @Description:生成表格个人
     * @Author: zhongdl
     * @Date:2022/4/20 15:46
     * @return: {@link org.fzzn.core.model.msg.Message<java.util.List<com.hb.core.pojo.project.file.dto.ReviewItemSecondDto>> }
     **/
    @PostMapping("/reviewEvaluationForm/detailedPersonal")
    Message<List<ReviewItemSecondDto>> detailedPersonal(@RequestParam Long sectionId){
        List<ReviewItemSecondDto> itemSecondDtos = CollUtil.list(false);
        List<ReviewItemSecondDto> reviewItemSecondDtos = reviewItemSecondService.listReviewItemSecond(sectionId,FirstReviewItemTypeEnum.DETAILED_REVIEW.getCode());
        if (CollUtil.isEmpty(reviewItemSecondDtos)){
            return MsgUtil.success(reviewItemSecondDtos);
        }
        BidSectionDTO bidSectionDTO = bidSectionService.findBidAndProjectBySectionId(sectionId);
        if (bidSectionDTO != null){
            bidSectionDTO.setId(null);
        }
        if (CollUtil.isEmpty(reviewItemSecondDtos)){
            return MsgUtil.success(reviewItemSecondDtos);
        }
        List<EvaluationCommitteeMembers> evaluationCommitteeMembers = evaluationCommitteeMembersService.findBySectionId(sectionId);


        for (ReviewItemSecondDto reviewItemSecondDto : reviewItemSecondDtos) {
                //查询三级评审项
                List<ReviewItemThirdDto> reviewItemThirdDtos = reviewItemThirdService.selectReviewItemThirdListBySecondReviewItemId(reviewItemSecondDto.getId());
                reviewItemSecondDto.setReviewItemThirdDtos(reviewItemThirdDtos);
                //查询二级评审点
                List<EvaluationSecond> evaluationSeconds = evaluationSecondService.findBySectionIdAndSecondId(sectionId, reviewItemSecondDto.getId());
                reviewItemSecondDto.setEvaluationSeconds(evaluationSeconds);
                //查询三级评审点
                List<EvaluationThirdDTO> evaluationThirdDTOS = evaluationThirdService.resultOfReviewPoint(sectionId, reviewItemSecondDto.getId());
                reviewItemSecondDto.setEvaluationThirdDTOS(evaluationThirdDTOS);
                //查询二级未被淘汰的公司
                List<EvaluationSecond> orgIdList = evaluationSecondService.listNotEliminate(sectionId, reviewItemSecondDto.getId());
                reviewItemSecondDto.setOrgIdList(orgIdList);
                for (EvaluationCommitteeMembers evaluationCommitteeMember : evaluationCommitteeMembers) {
                    bidSectionDTO.to(reviewItemSecondDto);
                    ReviewItemSecondDto secondDto = reviewItemSecondDto.to(ReviewItemSecondDto.class);
                    //专家姓名
                    secondDto.setExpertId(evaluationCommitteeMember.getId());
                    secondDto.setExpertName(evaluationCommitteeMember.getMemberName());
                    secondDto.setConfirmationImage(evaluationCommitteeMember.getConfirmationImage());
                    //查询每个专家的评审表格
                    Long evaluationFormId = reviewEvaluationFormService.getReviewEvaluationFormDTO(sectionId, reviewItemSecondDto.getFileId(), 1, FirstReviewItemTypeEnum.DETAILED_REVIEW.getCode(),reviewItemSecondDto.getId(),evaluationCommitteeMember.getMemberId());
                    secondDto.setEvaluationFormId(evaluationFormId);
                    itemSecondDtos.add(secondDto);

                }

        }
        if (CollUtil.isNotEmpty(evaluationCommitteeMembers)){
            evaluationCommitteeMembers = evaluationCommitteeMembers.stream().filter(item -> StrUtil.isNotEmpty(item.getConfirmationImage()) && !"data:image/jpeg;base64,".equals(item.getConfirmationImage())).collect(Collectors.toList());
        }
        for (ReviewItemSecondDto itemSecondDto : itemSecondDtos) {
            itemSecondDto.setMembersList(evaluationCommitteeMembers);
        }
        return MsgUtil.success(itemSecondDtos);
    }

    /**
     * @param sectionId:
     * @Description:详细评审汇总
     * @Author: zhongdl
     * @Date:2022/4/20 17:14
     * @return: {@link Message< List< ReviewItemSecondDto>> }
     **/
    @PostMapping("/reviewEvaluationForm/detailedPersonalSummary")
    public Message<List<ReviewItemSecondDto>> detailedPersonalSummary( @RequestParam Long sectionId){
        List<ReviewItemSecondDto> reviewItemSecondDtos = reviewItemSecondService.listReviewItemSecond(sectionId,FirstReviewItemTypeEnum.DETAILED_REVIEW.getCode());
        if (CollUtil.isEmpty(reviewItemSecondDtos)){
            return MsgUtil.success(reviewItemSecondDtos);
        }
        BidSectionDTO bidSectionDTO = bidSectionService.findBidAndProjectBySectionId(sectionId);
        if (bidSectionDTO != null){
            bidSectionDTO.setId(null);
        }
        List<EvaluationCommitteeMembers> evaluationCommitteeMembers = evaluationCommitteeMembersService.findBySectionId(sectionId);

        if (CollUtil.isNotEmpty(evaluationCommitteeMembers)){
            evaluationCommitteeMembers = evaluationCommitteeMembers.stream().filter(item -> StrUtil.isNotEmpty(item.getConfirmationImage()) && !"data:image/jpeg;base64,".equals(item.getConfirmationImage())).collect(Collectors.toList());

        }

        for (ReviewItemSecondDto reviewItemSecondDto : reviewItemSecondDtos) {
            //评标表格id
            Long evaluationFormId = reviewEvaluationFormService.getReviewEvaluationFormDTO(sectionId, reviewItemSecondDto.getFileId(), 2, FirstReviewItemTypeEnum.DETAILED_REVIEW.getCode(),reviewItemSecondDto.getId(),null);
            reviewItemSecondDto.setEvaluationFormId(evaluationFormId);
            //查询三级评审项
            List<ReviewItemThirdDto> reviewItemThirdDtos = reviewItemThirdService.selectReviewItemThirdListBySecondReviewItemId(reviewItemSecondDto.getId());
            reviewItemSecondDto.setReviewItemThirdDtos(reviewItemThirdDtos);
            //设置项目名称
            bidSectionDTO.to(reviewItemSecondDto);

            //查询二级评审点
            List<EvaluationSecond> evaluationSeconds = evaluationSecondService.findBySectionIdAndSecondId(sectionId, reviewItemSecondDto.getId());
            reviewItemSecondDto.setEvaluationSeconds(evaluationSeconds);
            //查询三级评审点
            List<EvaluationThirdDTO> evaluationThirdDTOS = evaluationThirdService.resultOfReviewPoint(sectionId, reviewItemSecondDto.getId());
            reviewItemSecondDto.setEvaluationThirdDTOS(evaluationThirdDTOS);
            //查询二级未被淘汰的公司
            List<EvaluationSecond> orgIdList = evaluationSecondService.listNotEliminate(sectionId, reviewItemSecondDto.getId());
            reviewItemSecondDto.setOrgIdList(orgIdList);
            reviewItemSecondDto.setMembersList(evaluationCommitteeMembers);
        }
        return MsgUtil.success(reviewItemSecondDtos);

    }
    /**
     *
     * @Description:查询标段的报价评审
     * @Author: zhongdl
     * @Date:2022/4/20 21:22
     * @param sectionId:
     * @return: {@link Message< List< QuotationReviewExcelDTO>> }
     **/
    @PostMapping("/reviewEvaluationForm/quotationReview")
    public Message<List<QuotationReviewExcelDTO>> quotationReview( @RequestParam Long sectionId){
        List<QuotationReviewExcelDTO> list = CollUtil.list(false);
        //查询所有的单位
        List<EvaluationSecond> orgIdList = evaluationSecondService.listNotEliminate(sectionId, null);
        if (CollUtil.isEmpty(orgIdList)){
            return MsgUtil.success(list);
        }
        List<EvaluationSecond> evaluationSecondList = evaluationSecondService.listEvaluationSecond(sectionId, FirstReviewItemTypeEnum.QUOTATION_REVIEW.getCode());
        //评标表格id
        Long evaluationFormId = reviewEvaluationFormService.getReviewEvaluationFormDTO(sectionId, null, 2, FirstReviewItemTypeEnum.QUOTATION_REVIEW.getCode(),null,null);
        List<EvaluationCommitteeMembers> evaluationCommitteeMembers = evaluationCommitteeMembersService.findBySectionId(sectionId);

        if (CollUtil.isNotEmpty(evaluationCommitteeMembers)){
            evaluationCommitteeMembers = evaluationCommitteeMembers.stream().filter(item -> StrUtil.isNotEmpty(item.getConfirmationImage()) && !"data:image/jpeg;base64,".equals(item.getConfirmationImage())).collect(Collectors.toList());

        }
        for (EvaluationSecond evaluationSecond : orgIdList) {
            QuotationReviewExcelDTO quotationReviewExcelDTO = new QuotationReviewExcelDTO();
            BeanUtil.copyProperties(evaluationSecond,quotationReviewExcelDTO);
            quotationReviewExcelDTO.setEvaluationFormId(evaluationFormId);
            //  查询评分 //查询报价
            List<EvaluationSecond> orgEvaluationSecond = evaluationSecondList.stream().filter(item -> item.getOrgId().equals(evaluationSecond.getOrgId())).collect(Collectors.toList());
            if (CollUtil.isEmpty(orgEvaluationSecond)){
//                quotationReviewExcelDTO.setQuotedPrice("0");
//                quotationReviewExcelDTO.setEvaluationPrice(0.0);
//                quotationReviewExcelDTO.setFinalScore(0.0);
//
//                list.add(quotationReviewExcelDTO);
                continue;
            }
            if (orgEvaluationSecond.get(0).getFinalScore() == null){
                continue;
            }
            quotationReviewExcelDTO.setMembersList(evaluationCommitteeMembers);
            //得分
            quotationReviewExcelDTO.setFinalScore(orgEvaluationSecond.get(0).getFinalScore());
            //报价
            List<EvaluationThirdDTO> evaluationThirdDTOS = evaluationThirdService.resultOfReviewPoint(sectionId, orgEvaluationSecond.get(0).getSecondReviewItemId());
            List<EvaluationThirdDTO> orgThird = evaluationThirdDTOS.stream().filter(item -> item.getOrgId().equals(evaluationSecond.getOrgId())).collect(Collectors.toList());
            if(CollUtil.isEmpty(orgThird)){
                quotationReviewExcelDTO.setQuotedPrice("0");
                list.add(quotationReviewExcelDTO);
                continue;
            }
            if(quotationReviewExcelDTO.getFinalScore() == null){
                quotationReviewExcelDTO.setFinalScore(0.0);
            }
            quotationReviewExcelDTO.setQuotedPrice(orgThird.get(0).getQuotedPrice());
            list.add(quotationReviewExcelDTO);
        }
        return MsgUtil.success(list);
    }

    /**
     * @param sectionId:查询评分汇总
     * @Description:
     * @Author: zhongdl
     * @Date:2022/4/21 11:13
     * @return: {@link org.fzzn.core.model.msg.Message<java.util.List<com.hb.core.pojo.project.file.dto.ReviewItemSecondDto>> }
     **/
    @PostMapping("/reviewEvaluationForm/scoreSummary")
    public Message<ScoreSummaryExcelDTO> scoreSummary(@RequestParam Long sectionId){
        ScoreSummaryExcelDTO scoreExcelDTO = new ScoreSummaryExcelDTO();
        BidSectionDTO bidSectionDTO = bidSectionService.findBidAndProjectBySectionId(sectionId);
        if (bidSectionDTO != null){
            bidSectionDTO.setId(null);
        }
        BeanUtil.copyProperties(bidSectionDTO,scoreExcelDTO);

        List<ScoreSummarySecondDTO> list = CollUtil.list(false);
        //查询招标文件的二级评审项
         //详细评审二级
        List<ReviewItemSecondDto> detailedSecondList = reviewItemSecondService.listReviewItemSecond(sectionId, FirstReviewItemTypeEnum.DETAILED_REVIEW.getCode());
        List<ReviewItemSecondDto> quotationSecondList = reviewItemSecondService.listReviewItemSecond(sectionId, FirstReviewItemTypeEnum.QUOTATION_REVIEW.getCode());
        if (CollUtil.isEmpty(detailedSecondList) && CollUtil.isEmpty(quotationSecondList)){
            return MsgUtil.success(scoreExcelDTO);
        }


        //通过标段查询所有的三级点报价
        List<EvaluationThirdDTO> evaluationThirdDTO = evaluationThirdService.listEvaluationThirdDTO(sectionId, null,FirstReviewItemTypeEnum.DETAILED_REVIEW.getCode());
        List<EvaluationThirdDTO> quotationPointList = evaluationThirdService.listEvaluationThirdDTO(sectionId, null,FirstReviewItemTypeEnum.QUOTATION_REVIEW.getCode());
        List<EvaluationSecond> evaluationSecondList = evaluationSecondService.listEvaluationSecond(sectionId,FirstReviewItemTypeEnum.QUOTATION_REVIEW.getCode());

        //查询所有的单位
        List<EvaluationSecond> orgIdList = evaluationSecondService.listNotEliminate(sectionId, null);
        for (EvaluationSecond evaluationSecond : orgIdList) {
            Long orgId = evaluationSecond.getOrgId();
            ScoreSummarySecondDTO scoreSummaryExcelDTO = new ScoreSummarySecondDTO();
            List<ReviewItemSecondDto> reviewItemSecondDtos = CollUtil.list(false);
            BeanUtil.copyProperties(evaluationSecond,scoreSummaryExcelDTO);

            //设置每个评审项的分数
            for (ReviewItemSecondDto reviewItemSecondDto : detailedSecondList) {
                ReviewItemSecondDto reviewItemSecond = new ReviewItemSecondDto();
                //公司的三级点评分
                List<EvaluationThirdDTO> orgEvaluationThirdList = evaluationThirdDTO.stream().filter(evaluationThird -> orgId.equals(evaluationThird.getOrgId()) && evaluationThird.getSecondReviewItemId().equals(reviewItemSecondDto.getId())).collect(Collectors.toList());
                List<String> collect = orgEvaluationThirdList.stream().map(EvaluationThirdDTO::getFinalScore).collect(Collectors.toList());
                int expertCount = orgEvaluationThirdList.stream().map(EvaluationThirdDTO::getExpertId).collect(Collectors.toSet()).size();
                //去掉最高最低
                if (Integer.valueOf(2).equals(reviewItemSecondDto.getScoreTotalCondition())){
                    List<Long> expertIdList = evaluationSecondList.stream().filter(item -> item.getSecondReviewItemId().equals(reviewItemSecondDto.getId()) && orgId.equals(item.getOrgId()))
                            .sorted(Comparator.comparing(EvaluationSecond::getFinalScore)).map(EvaluationSecond::getExpertId).collect(Collectors.toList());
                    if (CollUtil.size(expertIdList) > 2){
                        expertIdList.remove(expertIdList.size() - 1);
                        expertIdList.remove(0);
                    }
                    orgEvaluationThirdList = orgEvaluationThirdList.stream().filter(evaluationThird -> expertIdList.contains(evaluationThird.getExpertId())).collect(Collectors.toList());
                    collect = orgEvaluationThirdList.stream().map(EvaluationThirdDTO::getFinalScore).collect(Collectors.toList());
                    expertCount = orgEvaluationThirdList.stream().map(EvaluationThirdDTO::getExpertId).collect(Collectors.toSet()).size();
                }
                reviewItemSecond.setFinalScore(getAverageSum(collect,expertCount));
                reviewItemSecond.setId(reviewItemSecond.getId());
                reviewItemSecondDtos.add(reviewItemSecond);
            }
            ReviewItemSecondDto reviewItemSecond = new ReviewItemSecondDto();
            if (CollUtil.isEmpty(quotationSecondList)){
                continue;

            }
            //计算评标价算法
            List<EvaluationThirdDTO> orgEvaluationSecond = quotationPointList.stream().filter(item -> item.getOrgId().equals(orgId)).collect(Collectors.toList());
            if (CollUtil.isEmpty(orgEvaluationSecond)){
                continue;

            }
            if (orgEvaluationSecond.get(0).getFinalScore() == null){
                continue;
            }
            reviewItemSecond.setFinalScore( Double.valueOf(orgEvaluationSecond.get(0).getFinalScore()));
            scoreSummaryExcelDTO.setQuotedPrice(CollUtil.isEmpty(orgEvaluationSecond) ? "0" : orgEvaluationSecond.get(0).getQuotedPrice());
            reviewItemSecondDtos.add(reviewItemSecond);
            scoreSummaryExcelDTO.setReviewItemSecondDtos(reviewItemSecondDtos);
            //查询工期
            OpeningBidTender openingBidTender = openingBidTenderService.getOpeningBidTenderBySection(sectionId, orgId);
            if (openingBidTender != null && StrUtil.isNotEmpty(openingBidTender.getDecryptContent())){
                JSONObject jsonObject = JSONUtil.parseObj(openingBidTender.getDecryptContent());
                scoreSummaryExcelDTO.setPeriod(jsonObject.get("工期（天）",String.class));
            }
            //设置投标报价
            list.add(scoreSummaryExcelDTO);
        }
        ReviewItemSecondDto reviewItemSecondDto = new ReviewItemSecondDto();
        reviewItemSecondDto.setSecondReviewItemName("报价评审");
        detailedSecondList.add(reviewItemSecondDto);
        //查询评分汇总表格id
        Long evaluationFormId = reviewEvaluationFormService.getReviewEvaluationFormDTO(sectionId, null, 2, -1,null,null);
        scoreExcelDTO.setEvaluationFormSummaryId(evaluationFormId);
        //评分结论
        Long evaluationFormConclusionId = reviewEvaluationFormService.getReviewEvaluationFormDTO(sectionId, null, 2, 0,null,null);
        scoreExcelDTO.setEvaluationFormConclusionId(evaluationFormConclusionId);
        scoreExcelDTO.setReviewItemSecondList(detailedSecondList);
        scoreExcelDTO.setOrgList(list);
        return MsgUtil.success(scoreExcelDTO);

    }






     public static Double getAverageSum(List<String> strValue,int expertCount){
         List<Double> list = CollUtil.list(false);
         if (CollUtil.isEmpty(strValue)){
             return 0.0;
         }
         for (String str : strValue) {
             if (StrUtil.isEmpty(str)){
                 list.add(0.0);
                 continue;
             }
             list.add(Double.parseDouble(str));
         }
         Double value = list.stream().reduce(Double::sum).get();
         BigDecimal two = new BigDecimal(value / expertCount);
         return two.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
     }
}
